<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      let arr = [3, 6, 3, 6]
      function getArr(a) {
        // console.log(a)
        let sum = 0
        let ouNumber = 0 //计算偶数的个数
        let num = 0
        for (let i = 0; i < a.length; i++) {
          if (a[i] % 2 === 0) {
            num = ++ouNumber
          }
        }
        //如果偶数的个数不等于数组的长度
        if (num !== a.length) {
          for (let j = 0; j < a.length; j++) {
            if (a[j] % 2 !== 0) {
              sum += a[j]
            }
          }
          return sum / num
        }
        //如果偶数的个数等于数组的长度  返回零
        if (num === a.length) {
          return 0
        }
        // console.log(num)
      }
      // return sum / a.length

      // if (arr[i] % 2 === 0) {
      //       ouNumber++
      //       if (ouNumber === arr.length) {
      //         return (sum = 0)
      //       } else if (arr[i] % 2 !== 0) {
      //         sum += arr[i]
      //         return sum / arr.length
      //       }
      //     }
      //   }
      console.log(getArr(arr))
    </script>
  </body>
</html>
